﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Menus;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.Menus
{
    public class QueryPIdCommandHandler : IRequestHandler<QueryPIdCommand, APIResult<object>>
    {
        private readonly IBaseRepository<Menu> menuRep;

        public QueryPIdCommandHandler(IBaseRepository<Menu> menuRep)
        {
            this.menuRep = menuRep;
        }
        public async Task<APIResult<object>> Handle(QueryPIdCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();

            var model = menuRep.GetAll().Result.Where(p => p.PId == request.MenuId).Count();

            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = model;
            return await Task.FromResult(result);
        }
    }
}
